<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>显示所有</title>
		<!-- Bootstrap -->
   		<link href="css/bootstrap.css" rel="stylesheet">
		<link href="css/bootstrap-table.css" rel="stylesheet"/>
        <link href="css/bootstrap-editable.css" rel="stylesheet"/>
        <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
        <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
        <!--[if lt IE 9]>
          <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
          <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
	</head>
	<body>
        <!--导航栏开始-->
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">预热班学员管理系统</a>
                </div>

            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav navbar-right">
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="/rsm/showSuggest.html">查看学生意见</a></li>
                        <li>&nbsp;</li>
                        <li class="active"><a href="/rsm/showAnswer.html">查看学生提交的习题</a></li>
                        <li>&nbsp;</li>
                        <li class="active"><a href="/rsm/SubjectManager.html">习题管理</a></li>
                        <li>&nbsp;</li>
                        <li class="active"><a href="/rsm/selectclass.html">选择其他班级</a></li>
                        <li>&nbsp;</li>
                        <li class="active"><a href="javascript:void(0)" onclick="addNewClass()">添加新班级</a></li>
                        <li></li>
                    </ul>
                </ul>
            </div>
            </div>
        </nav>
        <!--导航栏结束-->
    <!--页面主体    -->
	<div class="container-fluid" align="center">
		<table id="mytable" data-toggle="table" data-url="/rsm/student/showAllByClassId.do">
			<thead>
				<tr>
				</tr>
			</thead>
		</table>
        <!--table工具栏开始-->
        <div id="toolbar">
            <div class="btn-group">
                <!--excel导入学生信息-->
                <button class="btn btn-default" onclick="openImport()">
                    <i class="glyphicon glyphicon-upload"></i>
                </button>
                <!--添加学生信息-->
                <button class="btn btn-default" onclick="openadd()">
                    <i class="glyphicon glyphicon-plus"></i>
                </button>
                <!--删除选中学生-->
                <button class="btn btn-default" onclick="deleteSelect()">
                   <i class="glyphicon glyphicon-trash"></i>
                </button>
                <!--导出学生信息-->
                <button class="btn btn-default" onclick="openExport()">
                    <i class="glyphicon glyphicon-download"></i>
                </button>
            </div>
        </div>
        <!--table工具栏结束-->

        <!-- 导入模态框（Modal） -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel">
                            导入学生信息
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form id="ImportForm" role="form" method="post" enctype="multipart/form-data" action="/rsm/student/importStudent.do">
                            <input  id="fileName" type="file" name="fileName"  />
                            <a href="javascript:void(0)" onclick="importUser()">开始导入</a>
                        </form>
                    </div>

                </div>
            </div>
        </div>

        <!-- 添加模态框（Modal） -->
        <div class="modal fade" id="myModa2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabe2">
                            添加学生信息
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form id="addForm" role="form" method="post" enctype="multipart/form-data" action="/rsm/student/addStudent.do">
                            <div class="form-group">
                                <label for="name">姓名</label>
                                <input type="text" class="form-control" name="name" id="name">
                            </div>
                            <div class="form-group">
                                <label for="age">年龄</label>
                                <input type="text" class="form-control" name="age" id="age">
                            </div>
                            <div class="form-group">
                                <label for="age">手机</label>
                                <input type="text" class="form-control" name="phone" id="phone">
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                         <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                         <button type="button" class="btn btn-primary" onclick="submitForm()">提交</button>
                     </div>
                </div>
            </div>
        </div>


        <!-- 添加模态框（Modal） -->
        <div class="modal fade" id="myModa3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabe3">
                            添加班级信息
                        </h4>
                    </div>
                    <div class="modal-body">
                        <form id="addNewClassForm" role="form" method="post" enctype="multipart/form-data" action="/rsm/class/addNewClass.do">
                            <div class="form-group">
                                <label for="name">班级名字</label>
                                <input type="text" class="form-control" name="className" id="className">
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" onclick="submitClassForm()">提交</button>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <!--页面主体结束    -->
	<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="js/jquery-3.3.1.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-table.js"></script>
    <script src="js/bootstrap-table-zh-CN.js"></script>
    <!--<script src="js/bootstrap-editable.min.js"></script>-->
    <!--<script src="js/bootstrap-editable.js"></script>-->
    <script src="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
    <script src="js/bootstrap-table-editable.js"></script>
    <!--自己的js代码-->
    <!--<script src="js/showallstudents.js"></script>-->
    <script>

        $("#mytable").bootstrapTable({
            method:'post',
            //显示搜索框
            search: true,
            //显示刷新按钮
            showRefresh:true,
            //显示切换视图（table/card）按钮
            showToggle:true,
            //是否显示内容列下拉框。
            showColumns:true,
            //设置为 true 会有隔行变色效果
            striped:true,
            //设置为 true 会在表格底部显示分页条
            pagination:true,
            pageSize: 50,
            pageList: [50,100], //可供选择的每页的行数（*）
            //是否显示列头showHeader:false
            showHeader:true,
            editable:true,
            //自定义工具栏
            toolbar:"#toolbar",
            toolbarAlign:'left',
            columns :[{
                field : 'checked',
                checkbox : true,
            },{
                title: '序号',
                field: '',
                align: 'center',
                formatter: function (value, row, index) {
                    return index+1;
                }
            },
                {
                    field : 'id',
                    title : '编号',
                    visible:false,
                },{
                    field : 'name',
                    title : '姓名',
                    editable: {
                        type: 'text',
                        title: '姓名',
                        validate: function (v) {
                            if (!v) return '不能为空';

                        }
                    }
                },{
                    field : 'age',
                    title : '年龄',
                    editable: {
                        type: 'text',
                        title: '年龄',
                        validate: function (v) {
                            if (!v) return '不能为空';

                        }
                    }
                },{
                    field : 'education',
                    title : '学历',
                    editable: {
                        type: 'select',
                        title: '学历',
                        source:[
                            {value:"硕士",text:"硕士"},
                            {value:"本科",text:"本科"},
                            {value:"大专",text:"大专"},
                            {value:"中专",text:"中专"},
                            {value:"高中",text:"高中"},
                            {value:"初中",text:"初中"}
                        ]
                    }
                },{
                    field : 'source',
                    title : '来源',
                    editable: {
                        type: 'select',
                        title: '来源',
                        source:[
                            {value:"国奥",text:"国奥"},
                            {value:"渠道",text:"渠道"},
                            {value:"网招",text:"网招"},
                            {value:"口碑",text:"口碑"}
                        ]
                    }
                },{
                    field : 'testscore',
                    title : '入班测试分数',
                    editable: {
                        type: 'text',
                        title: '入班测试分数',
                        validate: function (v) {
                            if (!v) return '不能为空';

                        }
                    }
                },{
                    field : 'payment',
                    title : '是否缴费',
                    editable: {
                        type: 'select',
                        title: '是否缴费',
                        source:[
                            {value:"是",text:"是"},
                            {value:"否",text:"否"}
                        ]
                    }
                },{
                    field : 'motivation',
                    title : '学习态度',
                    editable: {
                        type: 'select',
                        title: '学习态度',
                        source:[
                            {value:"A+",text:"A+"},
                            {value:"A",text:"A"},
                            {value:"A-",text:"A-"},
                            {value:"B+",text:"B+"},
                            {value:"B",text:"B"},
                            {value:"B-",text:"B-"},
                            {value:"C+",text:"C+"},
                            {value:"C",text:"C"},
                            {value:"C-",text:"C-"}
                        ]
                    }
                }, {
                    field : 'technical',
                    title : '技术能力',
                    editable: {
                        type: 'select',
                        title: '技术能力',
                        source:[
                            {value:"A+",text:"A+"},
                            {value:"A",text:"A"},
                            {value:"A-",text:"A-"},
                            {value:"B+",text:"B+"},
                            {value:"B",text:"B"},
                            {value:"B-",text:"B-"},
                            {value:"C+",text:"C+"},
                            {value:"C",text:"C"},
                            {value:"C-",text:"C-"}
                        ]
                    }
                },{
                    field : 'stable',
                    title : '稳定与否',
                    editable: {
                        type: 'select',
                        title: '稳定与否',
                        source:[
                            {value:"是",text:"是"},
                            {value:"否",text:"否"}
                        ]
                    }
                },{
                    field : 'schedule',
                    title : '预热进度',
                    editable: {
                        type: 'select',
                        title: '预热进度',
                        source: function () {
                            var result = [];
                            $.ajax({
                                url:'/rsm/schedule/showall.do',
                                async: false,
                                type: "get",
                                dataType:'json',
                                success: function (data, status) {
                                    $.each(data, function (key, value) {
                                        var xx = $.trim(value.sname);
                                        result.push({value:value.sid, text: xx});
                                    });
                                }
                            });
                            return result;

                        }
                    }
                },{
                    field : 'exceptionstate',
                    title : '异常状态',
                    visible:false,
                    editable: {
                        type: 'select',
                        title: '异常状态',
                        source:[
                            {value:"",text:""},
                            {value:"请假",text:"请假"},
                            {value:"退学",text:"退学"}
                        ]
                    }
                },{
                    field : 'focus',
                    title : '重点关注',
                    editable: {
                        type: 'select',
                        title: '重点关注',
                        source:[
                            {value:"是",text:"是"},
                            {value:"否",text:"否"}
                        ]
                    }
                },{
                    field : 'support',
                    title : '是否需要支持配合',
                    editable: {
                        type: 'select',
                        title: '是否需要支持配合',
                        source:[
                            {value:"是",text:"是"},
                            {value:"否",text:"否"}
                        ]
                    }
                },{
                    field : 'remark',
                    title : '备注',
                    editable: {
                        mode:"inline",
                        type: 'textarea',
                        title: '请输入内容',
                    }
                },{
                    field : 'zxteacher',
                    title : '咨询老师',
                    editable: {
                        type: 'select',
                        title: '咨询老师',
                        source: function () {
                            var result = [];
                            $.ajax({
                                url: '/rsm/zxteacher/showall.do',
                                async: false,
                                type: "get",
                                dataType:'json',
                                success: function (data, status) {
                                    $.each(data, function (key, value) {
                                        var xx = $.trim(value.name);
                                        result.push({value:value.id, text: xx});
                                    });
                                }
                            });
                            return result;

                        }
                    }

                },{
                    field : 'rbtime',
                    title : '入班时间',
                    editable: {
                        type: 'date',
                        title: '入班时间'
                    }
                },{
                    field : 'phone',
                    title : '手机',
                    editable: {
                        type: 'text',
                        title: '手机'
                    }
                },{
                    field : 'email',
                    title : '邮箱',
                    editable: {
                        type: 'text',
                        title: '邮箱'
                    }
                },{
                    field : 'wechat',
                    title : '微信',
                    editable: {
                        type: 'text',
                        title: '微信'
                    }
                },{
                    field : 'qq',
                    title : 'QQ号',
                    editable: {
                        type: 'text',
                        title: 'QQ号'
                    }
                }
            ],

            onEditableSave: function (field, row, oldValue, $el) {
                $.ajax({
                    type: "post",
                    url: "/rsm/student/updateOne.do",
                    data: row,
                    dataType: 'JSON',
                    success: function (data, status) {
                        if (status == "success") {
                            alert('提交数据成功');
                            $("#mytable").bootstrapTable('refresh');
                        }
                    },
                    error: function () {
                        alert('编辑失败');
                    },
                    complete: function () {

                    }

                });
            }
        });
        //打开新班级添加页面
        function addNewClass() {
            $('#myModa3').modal()
        }
        
        function openImport() {
            $('#myModal').modal()
        }

        function openadd() {
            $('#myModa2').modal()
        }

        //            删除选中
        function deleteSelect() {
            var a= $("#mytable").bootstrapTable('getSelections');
            if(a.length<=0){
                alert("请选中一行")
            }else{
                var b=JSON.stringify(a);
                var url="/rsm/student/deleteSelete.do";
                $.ajax({
                    dataType: "json",
                    traditional:true,//这使json格式的字符不会被转码
                    data: {"datalist":b},
                    type: "post",
                    url: url,
                    success : function (data) {
                        $("#mytable").bootstrapTable('refresh');
                        alert("删除成功！");
                    },
                });
            }
        }
        //           导入文件
        function importUser() {
            var x = $("#fileName").val();
            if(x){
                $("#ImportForm").submit();
            }else {
                alert("请选择要导入的文件");
            }

        }
        //           导出文件
        function openExport() {
            var x = $("#mytable").bootstrapTable('getSelections');
            if(x.length === 0){
                alert("请选择要导出的数据");
            }else {
                var ids = new Array(x.length);
                //获取所有id
                for (var i = 0; i < x.length; i++) {
                    ids[i] = x[i].id;
                }
                //console.info(ids);
                window.location.href="/rsm/student/exportMessage.do?ids="+ids;
            }
        }

        function submitForm() {
            $("#addForm").submit();
        }

        function submitClassForm() {
            $("#addNewClassForm").submit();
        }


    </script>
     </body>
</html>
